package web;

import ejbEntity.Artista;
import ejbSessionBeans.ArtistaFacadeLocal;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author bbaquero
 */
public class MostrarArtista extends HttpServlet {

    @EJB
    private ArtistaFacadeLocal artistaFacade;

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            out.println("<html>");
            out.println("<head>");
            out.println("<title>))) RAW ((( Artistas por la "+ request.getParameter("ini") +"</title>");
            out.println("<link href=\"styleRAW.css\" rel=\"stylesheet\" type=\"text/css\" /></head>");
            out.println("<body>"+ Resources.setSideBar() + Resources.setWordsNav() + "<br><br>");

            out.println("<div id=content>");
            out.println("<div id=infobar><center><b><font color=white size=2 face=verdana>Artistas por la " + request.getParameter("ini") + "</b></font></center></div>");
            out.println("<center>");
            List<Artista> arts = artistaFacade.findByIni(request.getParameter("ini"));
            for (Iterator it = arts.iterator(); it.hasNext();) {
                Artista elem = (Artista) it.next();
                out.println(" <a href=MostrarAlbum?arti=" + elem.getIdArtista() + ">" + elem.getNombre() + " </a><br />");
            }
            out.println("<br><br><br>"); //Saltos de linea obligatorios para correcta vision de pagina junto con la barra de navegacion de letras.
            out.println("</center></div></body>");
            out.println("</html>");

        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
